package com.estar.assistsurvy.utils;

import com.estar.assistsurvy.controller.ActivityController;
import com.estar.assistsurvy.entity.TSRole;
import com.estar.assistsurvy.entity.User;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

public class SharepreferenceUtils {

	private static Activity activity;
	
	public static void saveUser(User user){
		activity=ActivityController.getCurrentActivity();		
		Log.i("wl", "当前页面activity---》"+ActivityController.getCurrentActivity());

		SharedPreferences preference=activity.getSharedPreferences("user", Context.MODE_PRIVATE);
		Editor editor=preference.edit();
		editor.putString("uuid", user.getId());
		editor.putString("password", user.getPassword());
		editor.putString("phoneNumber", user.getPhoneNumber());
		editor.putString("officePhone", user.getOfficePhone());
		editor.putString("email", user.getEmail());
		editor.putString("isvalid", user.getIsvalid());
		editor.putString("createDate", user.getCreateDate());
		editor.putString("realName", user.getRealName());
		editor.putString("updateDate", user.getUpdateDate());
		editor.putString("userName", user.getUserName());
		editor.putString("idcard", user.getIdcard());
		editor.putString("gender", user.getGender());
		editor.putString("age", user.getAge());
		editor.putString("headUrl", user.getHeadUrl());
		editor.putString("address", user.getAddress());
		editor.putString("status", user.getStatus());
		editor.putString("deleteFlag", user.getDeleteFlag());
		editor.putString("authenticationState", user.getAuthenticationState());
		editor.putString("dataSources", user.getDataSources());
		editor.commit();
		
		preference=activity.getSharedPreferences("username", Context.MODE_PRIVATE);
		editor=preference.edit();
		editor.putString("telephone", user.getPhoneNumber());
		editor.commit();
	}
	
	public static void saveRole(TSRole role){
		activity=ActivityController.getCurrentActivity();
		SharedPreferences preference=activity.getSharedPreferences("role", Context.MODE_PRIVATE);
		Editor editor=preference.edit();
		editor.putString("id", role.getId());
		editor.putString("rolecode", role.getRolecode());
		editor.putString("rolename", role.getRolename());
		editor.putString("updateName", role.getUpdateName());
		editor.putString("updateDate", role.getUpdateDate());
		editor.putString("updateBy", role.getUpdateBy());
		editor.putString("createName",role.getCreateName());
		editor.putString("createDate", role.getCreateDate());
		editor.putString("createBy", role.getCreateBy());
		editor.commit();
	}
}
